﻿using System;
using System.Diagnostics;
using System.Reflection;
using Super_Management_Mayhem.GameRoot;
using Super_Management_Mayhem.Screens.Menu.SelectPlayers;
using Super_Management_Mayhem.Screens.Playing.GameMode;
using Transformable_Engine_v2.Engine;
using Transformable_Engine_v2.Engine.Global;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem
{
    internal class Program
    {
        public const bool SKIP_PLAYER_CONFIG = false;
        private const bool DEBUG_START = true;
        const SelectPlayers.PlayerCount DEBUG_PLAYERS = SelectPlayers.PlayerCount.Two;
        const GameMode.GameModes DEBUG_GAME_MODE = GameMode.GameModes.MoneyMayhem;

        private static void Main(string[] argc)
        {
            Log.LogSeverity = Log.Severity.Info;
            if(argc.Length == 0 && !DEBUG_START)
            {
                var selectScreenProperties = new GameProperties {
                                                                BackgroundColor = Color.Black,
                                                                GridSize = 16,
                                                                IconPath = null,
                                                                KeyboardEnabled = true,
                                                                MouseEnabled = false,
                                                                GamepadEnabled = false,
                                                                ShowGrid = false,
                                                                ScreenSize = new TE_Vector2(40, 32),
                                                                Style = GameProperties.WindowStyle.Windowed,
                                                                Title = "Super Management Mayhem [Config]"
                                                            };

                var configMenu = new Config();

                Game.Start(configMenu, selectScreenProperties);

                //Execute the same program, but with the number of players specified
                Process.Start(Assembly.GetEntryAssembly().Location, 
                              String.Format("{0} {1} {2}", configMenu.Players.ToString(), configMenu.GameMode.ToString(), 2));

                return;
            }

            var playerCount = DEBUG_START ? DEBUG_PLAYERS : (SelectPlayers.PlayerCount) Enum.Parse(typeof(SelectPlayers.PlayerCount), argc[0]);
            var gameMode = DEBUG_START ? DEBUG_GAME_MODE : (GameMode.GameModes) Enum.Parse(typeof(GameMode.GameModes), argc[1]);
            int teamCount = DEBUG_START ? 2 : Convert.ToInt32(argc[2]);

            var smmProperties = new GameProperties {
                                                       BackgroundColor = Color.Black,
                                                       GridSize = 16,
                                                       IconPath = "Content/Icon/Icon.png",
                                                       KeyboardEnabled = true,
                                                       MouseEnabled = false,
                                                       GamepadEnabled = false,
                                                       ShowGrid = false,
                                                       Style = GameProperties.WindowStyle.Titlebar,
                                                       Title = "Super Management Mayhem",
                                                       TargetFps = 40,
                                                   };

            switch(playerCount)
            {
                case SelectPlayers.PlayerCount.One:
                    smmProperties.ScreenSize = new TE_Vector2(40, 32);
                    break;
                case SelectPlayers.PlayerCount.Two:
                    smmProperties.ScreenSize = new TE_Vector2(80, 32);
                    break;
                case SelectPlayers.PlayerCount.Three:
                    smmProperties.ScreenSize = new TE_Vector2(120, 32);
                    break;
                case SelectPlayers.PlayerCount.Four:
                    smmProperties.ScreenSize = new TE_Vector2(80, 60);
                    break;
                case SelectPlayers.PlayerCount.Six:
                    smmProperties.ScreenSize = new TE_Vector2(120, 60);
                    break;
                case SelectPlayers.PlayerCount.Eight:
                    smmProperties.ScreenSize = new TE_Vector2(160, 60);
                    break;
            }
            
            Game.Start(new SuperManagementMayhem(playerCount, gameMode, teamCount), smmProperties);
            
        }
    }
}
